package spring_test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MethodInjectionTest {
	public static void main(String[] args) {
		ApplicationContext context;
		context = getContext();
		Warrior warrior = (Warrior) context.getBean("warriorBean");
		System.out.println(warrior.getWeapon());
		
//		System.out.println(warrior.getWeapon().hashCode());
//		Warrior warrior1 = (Warrior) context.getBean("warriorBean");
//		System.out.println(warrior.getWeapon().hashCode());
	}

	public static ApplicationContext getContext() {
		return new ClassPathXmlApplicationContext("spring_test/method_injection_conf.xml");
	}
}

abstract class Warrior {
	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

//	public Weapon getWeapon() {
//		return ((Weapon) MethodInjectionTest.getContext().getBean("gunWeaponBean"));
//	}
	 public abstract Weapon getWeapon() ;
}

class Weapon {
	private String name;
	private float weight;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public float getWeight() {
		return weight;
	}

	public void setWeight(float weight) {
		this.weight = weight;
	}

	@Override
	public String toString() {

		return "weapon : " + name + "\n" + "weight : " + weight + "Kg";
	}
}